Friday, February 29, 2008

Run ffmpeg command with php

Hi,

In my last article I have tackled the problem for ffmpeg
installation when u dont have YUM installed on your server,
on same day I have again faced problem with execution of
ffmpeg commands from php and I have found below solution
for this on google

array("pipe", "r"), // stdin is a pipe that the child will
read from
1 => array("pipe", "w"), // stdout is a pipe that the child will
write to
2 => array("pipe", "w") // stderr is a file to write to
);

$pipes= array();
$process = proc_open($cmd, $descriptorspec, $pipes);

$output= "";

if (!is_resource($process)) return false;

#close child's input imidiately
fclose($pipes[0]);

stream_set_blocking($pipes[1],false);
stream_set_blocking($pipes[2],false);

$todo= array($pipes[1],$pipes[2]);

while( true ) {
$read= array();
if( !feof($pipes[1]) ) $read[]= $pipes[1];
if( !feof($pipes[2]) ) $read[]= $pipes[2];

if (!$read) break;

$ready= stream_select($read, $write=NULL, $ex= NULL, 2);

if ($ready === false) {
break; #should never happen - something died
}

foreach ($read as $r) {
$s= fread($r,1024);
$output.= $s;
}
}

fclose($pipes[1]);
fclose($pipes[2]);

$code= proc_close($process);

return $output;
}

Monday, February 25, 2008

How to Install ffmpeg?

Hi Folks,

I have spent hell three hours on finding the quick ffmpeg installer, and on my system YUM is also not working
I guess this similar kind of problem will be there with you also. Following are the easy stpes to install FFMPEG on your sever
My System is RedHat EL 4.

FFMPEG installation for RedHat EL 4 - i386
This installation will run probably for all i386 systems.

# rpm -Uvh --nodeps ftp://ftp.univie.ac.at/systems/linux/dag/redhat/el4/en/i386/RPMS.dag/ffmpeg-0.4.9-0.9.20070530.el4.rf.i386.rpm
# rpm -Uvh --nodeps ftp://ftp.pbone.net/mirror/atrpms.net/el4-i386/atrpms/stable/libogg0-1.1.3-7.el4.at.i386.rpm
# rpm -Uvh --nodeps ftp://ftp.univie.ac.at/systems/linux/dag/redhat/el4/en/i386/dag/RPMS/gsm-1.0.10-6.el4.rf.i386.rpm
# rpm -Uvh --nodeps ftp://ftp.pbone.net/mirror/atrpms.net/el4-i386/atrpms/stable/libmp3lame0-3.97-16.el4.i386.rpm
# rpm -Uvh --nodeps ftp://ftp.pbone.net/mirror/atrpms.net/el4-i386/atrpms/stable/libvorbis0-1.1.2-5.el4.at.i386.rpm
# rpm -Uvh --nodeps ftp://ftp.pbone.net/mirror/atrpms.net/el4-x86_64/atrpms/stable/libvorbisenc2-1.1.2-5.el4.at.i386.rpm
# rpm -Uvh --nodeps ftp://ftp.univie.ac.at/systems/linux/dag/redhat/el4/en/i386/RPMS.dag/xvidcore-1.1.3-1.el4.rf.i386.rpm
# rpm -Uvh --nodeps ftp://ftp.univie.ac.at/systems/linux/dag/redhat/el4/en/i386/dag/RPMS/x264-0.0.0-0.4.20070529.el4.rf.i386.rpm
# rpm -Uvh --nodeps ftp://ftp.pbone.net/mirror/atrpms.net/el4-i386/atrpms/stable/libfaac0-1.25-2.el4.at.i386.rpm
# rpm -Uvh --nodeps ftp://ftp.pbone.net/mirror/atrpms.net/el4-x86_64/atrpms/stable/faad2-2.5-7.el4.at.i386.rpm

Get sample MPEG file
wget http://www.fileformat.info/format/mpeg/sample/031699cb978244b8a3adf1e81cb2ac7c/FORM.MPG

Convert MPEG from FLV
ffmpeg -i FORM.MPG -ar 22050 -ab 32 -f flv -s 320x240 -aspect 4:3 -y

Convert IMAGE From FLV
ffmpeg -i FORM.flv -deinterlace -an -ss 1 -t 00:00:01 -r 1 -y -s 320×240 -vcodec mjpeg -f mjpeg form.jpg

RPMS Taken From
http://rpm.pbone.net/

ffmpeg help Articles
http://ffmpeg.mplayerhq.hu/faq.html
http://www.luar.com.hk/blog/?p=670